#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: generation_and_timing_the_fibonacci_sequence.py
@date: 2025-07-21 17:03
@author: Falling Snow
@desc: 通过单线程的方式生成fibonacci数列, 同时计时, 值的注意的是, 这个程序很慢, 他的时间复杂度到了 O(2^n)
"""

import time


def print_fib(number: int) -> None:
    def fib(n: int) -> int:
        if n == 1:
            return 0
        elif n == 2:
            return 1
        else:
            return fib(n - 1) + fib(n - 2)

    print(f"fib({number}) 结果为: {fib(number)}")


def fibs_no_threading():
    """单线程获取fibonacci序列"""
    print_fib(40)
    print_fib(41)


if __name__ == '__main__':
    start = time.time()
    fibs_no_threading()
    fibs_no_threading()
    fibs_no_threading()

    end = time.time()

    print(f"获取数据完成, 共耗费{((end - start) / 3):.4f} second")
